// common.h文件
/* Includes ------------------------------------------------------------------*/
#include "flash.h"
#include "ymodem.h"
#include <stdio.h>
#include <string.h>

/* Constants used by Serial Command Line Mode */
#define CMD_STRING_SIZE 128

/* BootLoader macro and functions ------------------------------------------------------- */
// 修改存放地址
#define BootLoaderAddress (0x0000)                           // 占16K
#define ApplicationAddress (0x4000)                          // 占54K   APP地址
#define Save_Updata_Address (ApplicationAddress + 1024 * 54) // 占54K 存储升级APP地址
#define Ota_flag_Address (Save_Updata_Address + 54 * 1024)   //   Ota标志位
#define Ota_Bin_Size_Address (Ota_flag_Address + 4)
typedef void (*pFunction)(void);

#define PAGE_SIZE (0x200) /* 512 byte */

/* Compute the FLASH upload image size */
#define FLASH_IMAGE_SIZE (uint32_t)(FLASH_SIZE - (ApplicationAddress - BootLoaderAddress))

#define Read(x) (*((volatile unsigned long *)(x)))
/* Exported macro ------------------------------------------------------------*/
/* Common routines */
#define IS_AF(c) ((c >= 'A') && (c <= 'F'))
#define IS_af(c) ((c >= 'a') && (c <= 'f'))
#define IS_09(c) ((c >= '0') && (c <= '9'))
#define ISVALIDHEX(c) IS_AF(c) || IS_af(c) || IS_09(c)
#define ISVALIDDEC(c) IS_09(c)
#define CONVERTDEC(c) (c - '0')

#define CONVERTHEX_alpha(c) (IS_AF(c) ? ((c) - 'A' + 10) : ((c) - 'a' + 10))
#define CONVERTHEX(c) (IS_09(c) ? ((c) - '0') : CONVERTHEX_alpha(c))

#define SerialPutString(x) Serial_PutString((uint8_t *)(x))

typedef struct
{
    uint32_t size;
    char md5[35];
    uint32_t ota_flag;
} ota;

extern ota ota_data;
extern uint8_t tab_1024[1024];
/** @defgroup GPIO_Exported_Functions
 * @{
 */
void Int2Str(uint8_t *str, int32_t intnum);

uint32_t Str2Int(uint8_t *inputstr, int32_t *intnum);

uint32_t GetIntegerInput(int32_t *num);

uint32_t SerialKeyPressed(uint8_t *key);

uint8_t GetKey(void);

void SerialPutChar(uint8_t c);

void Serial_PutString(uint8_t *s);

void GetInputString(uint8_t *buffP);

uint32_t FLASH_PagesMask(__IO uint32_t Size);

void FLASH_DisableWriteProtectionPages(void);

void SerialDownload(void);

void SerialUpload(void);


/************************ (C) COPYRIGHT FudanMicroelectronics *****END OF FILE****/